package com.zoe.app.config;

import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

/**
 * @author Zoe.Zhang
 * @date 2021/10/07
 * @description 自定义数据异常处理
 */
@Configuration
public class MyErrorAttribute extends DefaultErrorAttributes {
    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
        Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, options);
        if (((Integer) errorAttributes.get("status")) >= 500) {
            errorAttributes.put("message", "自定义之-服务器内部异常");
        }
        return errorAttributes;
    }
}
